package com.eyet.comeon.ui;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

public class UI {
	
	
    private static final int DIALOG_0 = 1; //只有确定按钮
    private static final int DIALOG_1 = 2; //网络设置对话框
    
	//创建进度条--圆形
    public static ProgressDialog createProgressDialog(Context con,String title,String message){
    	final ProgressDialog pd = new ProgressDialog(con);
    	pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条   
    	pd.setTitle(title);//设置标题  
    	pd.setMessage(message);//设置消息
    	pd.setIndeterminate(true);//设置进度条是否为不明确   
    	pd.setCancelable(true);//设置进度条是否可以按退回键取消  
    	return pd;
    }
	//创建对话框
	public static void createDialog(final Context con,String msg,int id) {
		AlertDialog.Builder builder = new AlertDialog.Builder(con);	
		switch(id) {
		case DIALOG_0:
	        builder.setTitle("提示");
	        builder.setMessage(msg);
	        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
	        	public void onClick(DialogInterface dialog, int whichButton) {
	        		dialog.dismiss();
	        	}
	        });
	        break;
		case DIALOG_1:
		    builder.setTitle("设置网络");
		    builder.setMessage(msg);
	        builder.setPositiveButton("设置网络", new DialogInterface.OnClickListener() {
	        	public void onClick(DialogInterface dialog, int whichButton) {
	        		con.startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
	        	}
	        });
	        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
	            public void onClick(DialogInterface dialog, int whichButton) {
	            	dialog.dismiss();
	            }
	        });
	        break;
		}
		
		builder.create().show();
		
	}

	//退出应用程序
	public static void exit(Context con){
		Intent startMain = new Intent(Intent.ACTION_MAIN);
		startMain.addCategory(Intent.CATEGORY_HOME);
		startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		con.startActivity(startMain);
		System.exit(0);
	}
}